package com.tcl.aota.admin.controller;

import com.tcl.aota.admin.dto.Result;
import com.tcl.aota.admin.manager.AppManager;
import com.tcl.aota.admin.util.RequestUtil;
import com.tcl.aota.common.constants.Constants;
import com.tcl.aota.manage.CurefManage;
import com.tcl.aota.persistent.model.Admin;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Curef Controller
 *
 * @author kelong
 * @date 5/7/15
 */
@Controller
public class CurefController {
    @Resource
    private CurefManage curefManage;

    @Resource
    private AppManager appManager;


    /**
     * 模糊查找或获取全部product
     *
     * @param product
     * @return
     */
    @RequestMapping(value = "/curef/products", method = RequestMethod.GET)
    @ResponseBody
    public Result products(@RequestParam(value = "product", required = false) String product) {
        return Result.get(curefManage.selectProduct(product), Constants.Common.SUCCESS);
    }

    /**
     * 通过product数组获取curef列表
     *
     * @return
     */
    @RequestMapping(value = "/curef/list", method = RequestMethod.GET)
    @ResponseBody
    public Result list(HttpServletRequest request) {
        Admin admin = RequestUtil.getSessionUser(request);
        int flag = 0;
        if (admin != null) {
            flag = admin.getAdminFlag();
        }
        return appManager.productCuref(flag);
    }
}
